<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/1/21
  Time: 14:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>修改评分</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../js/jquery.min.3.1.0.js"></script>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <script src="../../layuiadmin/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<form id="update" class="layui-form" action="/SaveEvaluateServlet" lay-filter="example" method="post">
    <table class="layui-hide" id="test"></table>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户账号</label>
            <div class="layui-input-inline">
                <input type="text" name="consumerAccount" value="${user.uAccount}" lay-verify="bid" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-inline">
                <select name="consumerName">
                    <c:forEach var="g" items="${goodsList}">
                        <option value="${g.goId}"><c:out value="${g.goName}" /></option>
                    </c:forEach>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">评分等级</label>
            <div class="layui-input-inline">
                <select name="score">
                    <option value="1" <c:if test="${evaluate.evaluateScore==1}">selected="selected"</c:if>>1</option>
                    <option value="2" <c:if test="${evaluate.evaluateScore==2}">selected="selected"</c:if>>2</option>
                    <option value="3" <c:if test="${evaluate.evaluateScore==3}">selected="selected"</c:if>>3</option>
                    <option value="4" <c:if test="${evaluate.evaluateScore==4}">selected="selected"</c:if>>4</option>
                    <option value="5" <c:if test="${evaluate.evaluateScore==5}">selected="selected"</c:if>>5</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">评价图片</label>
            <div class="layui-input-inline">
                <input type="text" name="img" value="${evaluate.evaluatePhoto}" lay-verify="price" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户描述</label>
            <div class="layui-input-inline">
                <input type="text" name="desc" value="${evaluate.evaluateDescribe}" lay-verify="count" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1" >立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <input name="consumerId" value="${user.uID}" style="display: none">
    <input name="id" value="${evaluate.evaluateId}" style="display: none">
</form>

<script>

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //验证修改商品页面的输入框
        form.verify({
            //评分只能选择1-5
            score: function (value) {
                if (!/[1-5]$/.test(value)) {
                    return '评分只能选择1-5';
                }
            }
            , desc: function (value) {
                if (!/[\u4e00-\u9fa5]+$/.test(value)) {
                    return '用户描述必须包含文字';
                }
            }
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });


        //监听提交
        form.on('submit(demo1)', function (data) {
            /* document.getElementById("update").submit();
             var index = parent.layer.getFrameIndex(window.name);
             parent.layer.close(index);*/
            $.ajax({
                type: "POST",
                url:"../../UpdataEvaluateServlet",
                data:$('#update').serialize(),// 序列化表单值
                async: false,
                success: function(data) {
                    alert(data.msg);
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            });
            return false;
        })
    })
</script>
</body>
</html>
